Blacklist binary target names
authorYoong Kang Lim <yoongkang.lim@gmail.com>
Wed, 3 Jun 2015 13:35:44 +0000 (23:35 +1000)
committerYoong Kang Lim <yoongkang.lim@gmail.com>
Fri, 5 Jun 2015 16:48:26 +0000 (02:48 +1000)
Some binary targets caused problems as
the directory names exist in target/debug. When
the compilation step fails, the error
message was also not descriptive.

This commit adds a blacklist and a more
descriptive error message.

See #1618.

src/cargo/util/toml.rs
tests/test_cargo_compile.rs

index 37857bbb8cf3f307974c912d64c88c64a4318124..ed13953c0dd651d0c947733e20f822d510bfd9cd 100644 (file)
@@ -423,6 +423,15 @@ impl TomlManifest {
             None => inferred_bin_targets(&project.name, layout)
         };
 
+        let blacklist = vec!["build", "deps", "examples", "native"];
+
+        for bin in bins.iter() {
+            if blacklist.iter().find(|&x| *x == bin.name) != None {
+                return Err(human(&format!("the binary target name `{}` is forbidden", 
+                                          bin.name)));
+            }
+        }
+
         let examples = match self.example {
             Some(ref examples) => examples.clone(),
             None => inferred_example_targets(layout),
index 0583479581b4eb96a9c49b756309b01f5fd1b7ff..e63647a9831963a55907880fef99773a42bb44da 100644 (file)
@@ -158,6 +158,29 @@ Caused by:
 "))
 });
 
+test!(cargo_compile_with_forbidden_bin_target_name {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            authors = []
+            version = "0.0.0"
+
+            [[bin]]
+            name = "build"
+        "#);
+
+    assert_that(p.cargo_process("build"),
+                execs()
+                .with_status(101)
+                .with_stderr("\
+failed to parse manifest at `[..]`
+
+Caused by:
+  the binary target name `build` is forbidden
+"))
+});
+
 test!(cargo_compile_with_invalid_lib_target_name {
     let p = project("foo")
         .file("Cargo.toml", r#"